/**
 * SharePoint Abstration Layer
 * @class A singleton class that provides the API for communicating SharePoint servers.
 * @requires SPServices
 * @property {Array} User Keeps data about the current user (false if no user was detected).
 * @version 0.1
 */
var SharePoint = new function () {
	
	/**
	 * Possible keys are:
	 * * Name - Account name of the user
	 */
	 this.User = false;
	
	/**
	 * Authenticate to the SharePoint server with a given account.
	 * @param {String} User The username of the account to change to.
	 * @param {String} Pass The password of the account that has to be authenticated.
	 * @returns {Boolean} True on success, false upon failure.
	 */
	this.Authenticate = function (User, Pass) {
		
		var success = false;
		
		$().SPServices ({
			operation: "Login",
			async: false,
			username: User,
			password: Pass,
			completefunc: function (result, status) {
				success = (status == "success");
			}
		});
		
		return success;
	}
	
	/**
	 * Connect the SharePoint object to a new server
	 * @returns {Boolean} True upon success, false upon failure.
	 */
	this.Initialize = function (URL) {
		$().SPServices.defaults.webURL = URL;
		this.URL = URL;
		return true;
	}
		
	/**
	 * Update the SharePoint object to contain latest configuration.
	 * @returns Boolean True on success, false upon failure.
	 */
	 this.Refresh = function () {
		// Retrieve data about the current user
		self.User = [];
		// self.User["Name"] = $().SPServices.SPGetCurrentUser({debug: true})
		// TODO: add more user fields
	 }
}

